//
//  TMTopView.swift
//  GZWeibo007
//
//  Created by denjunjie1 on 15/12/24.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

class TMTopView: UIView {
    
    
    
    var comments : TMComments? {
        
        didSet{
            
            
            self.nameLabel.text = comments?.user?.screen_name
            self.timeLabel.text = comments?.created_at
            //            print("\(comments?.id)")
            
            
            if  comments?.user?.verified == true {
                
                vipView.image  = UIImage(named: "common_icon_membership")
            }
            else{
                
                vipView.image = UIImage(named: "common_icon_membership_expired")
            }
            
            
            self.iconView.sd_setImageWithURL(NSURL(string:(comments?.user?.profile_image_url)!), placeholderImage: nil)
            
            
        }
    }
    
    
    
    
    
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        // 修改颜色
        //        self.backgroundColor = UIColor.brownColor()
        
        // 准备UI
        prepareUI()
        
        nameLabel.text = "gg"
        timeLabel.text = "soon"
        
    }
    
    private func prepareUI() {
        // 1.添加子控件
        //        addSubview(separatorView)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(vipView)
        
        // 2.添加约束
        //        separatorView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        
        // 头像
        iconView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        
        // 名称
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        
        // 时间
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        
        vipView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLabel, size: CGSize(width: 14, height: 14), offset: CGPoint(x: 8, y: 0))
        
    }
    
    //    private lazy var separatorView: UIView = {
    //        let view = UIView()
    //
    //        // 设置背景
    //        view.backgroundColor = UIColor(white: 0.95, alpha: 1)
    //
    //        return view
    //        }()
    
    
    var isVip : Bool = false {
        
        didSet {
            
            if (isVip != false) {
                
                vipView.image = UIImage(named: "common_icon_membership")
                
                return
            }else
            {
                vipView.image = UIImage(named: "common_icon_membership_expired")
                
            }
            
        }
        
    }
    
    /// 用户头像
    lazy var iconView: UIImageView = UIImageView(image: UIImage(named: "avatar"))
    
    /// 用户名称
    lazy var nameLabel: UILabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
    
    /// 微博时间
    lazy var timeLabel: UILabel = UILabel(color: UIColor.orangeColor(), fontSize: 9)
    
    
    lazy var vipView = UIImageView()
}
